package backend;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;

import main.SULauncher;

public class PropertiesInterperter {
	private SUProperties properties;

	public PropertiesInterperter() {
		properties = new SUProperties();
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Dimension screenSize = toolkit.getScreenSize();
		defaultScreenSize = new Dimension(screenSize.width / 3,
				screenSize.height / 3);
		defaultScreenLocation = new Point(screenSize.width / 3,
				screenSize.height / 3);
	}

	private Dimension defaultScreenSize;

	public Dimension getWindowSize() {
		String height = properties.getProperty(SUProperties.HEIGHT);
		String width = properties.getProperty(SUProperties.WIDTH);
		try {
			int int_height = Integer.parseInt(height);
			int int_width = Integer.parseInt(width);
			return new Dimension(int_width, int_height);
		} catch (Exception e) {
			return defaultScreenSize;
		}
	}
	private static final int ESTIMATED_BAR_HEIGHT = 45; 
	public void setWindowSize(Dimension windowSize) {
		properties.setProperty(SUProperties.HEIGHT, Integer.toString(windowSize.height-ESTIMATED_BAR_HEIGHT));
		properties.setProperty(SUProperties.WIDTH,Integer.toString(windowSize.width));
		properties.saveProperties();
	}

	private Point defaultScreenLocation;

	public Point getWindowLocation() {
		String x_location = properties.getProperty(SUProperties.X_LOATION);
		String y_location = properties.getProperty(SUProperties.Y_LOCATIONS);
		try {
			int int_x_location = Integer.parseInt(x_location);
			int int_y_location = Integer.parseInt(y_location);
			return new Point(int_x_location, int_y_location);
		} catch (Exception e) {
			return defaultScreenLocation;
		}
	}

	public void setWindowLocation(Point location) {
		System.out.println(location);
		properties.setProperty(SUProperties.X_LOATION,Integer.toString(location.x));
		properties.setProperty(SUProperties.Y_LOCATIONS,Integer.toString(location.y+ESTIMATED_BAR_HEIGHT));
		properties.saveProperties();
	}
	public void resetLocSizeColor(){
		properties.remove(SUProperties.HEIGHT);
		properties.remove(SUProperties.WIDTH);
		properties.remove(SUProperties.X_LOATION);
		properties.remove(SUProperties.Y_LOCATIONS);
		properties.remove(SUProperties.BG_COLOR);
		properties.saveProperties();
	}
	public Color getBGColor(){
		String color = properties.getProperty(SUProperties.BG_COLOR);
		try {
		Color bg_color = new Color(Integer.parseInt(color));
		return bg_color;
		} catch (Exception e) {
			return Color.LIGHT_GRAY;
		}
	}
	public void setBGColor(Color color){
		properties.setProperty(SUProperties.BG_COLOR, Integer.toString(color.getRGB()));
		properties.saveProperties();
	}
}
